/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * newManagerGUI.java
 *
 * Created on May 12, 2012, 9:16:39 PM
 */
package GUI;
import java.beans.PropertyChangeEvent;
import javax.swing.event.ChangeEvent;
import system_interface.*;
import Simulation.*;
import java.awt.event.*;
/**
 *
 * @author Jeremy
 */

import java.util.*;

public class newManagerGUI extends javax.swing.JFrame {
    
    private final java.awt.Dimension DEFAULTSIZE = new java.awt.Dimension(450, 450);
    private javax.swing.JComboBox ReportChoices;
    
    private ArrayList<String> ReportLabels = new ArrayList<String>();
    private ArrayList<Report> Reports = new ArrayList<Report>();
            
    SystemInterface si;
    KitchenSimulator ks;
    CustomerSimulator cs;
    /** Creates new form newManagerGUI */
    public newManagerGUI(SystemInterface si, KitchenSimulator ks, CustomerSimulator cs) {
        initComponents();
        this.ks = ks;
        this.cs = cs;
        this.si = si;
        ReportPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
        CreateReports();
        CreateReportButtons();
        ActionListener refresh = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                UpdateAllReports();
            }
        };
        new javax.swing.Timer(100, refresh).start();
        
    }
    private void CreateReports() {
        Reports.add(new TableReport(si,new java.awt.Dimension(450,450)));
        ReportLabels.add("Table Status");
        Reports.add(new CustomerWaitingReport(si,DEFAULTSIZE));
        ReportLabels.add("Customer Queue");
        Reports.add(new CookingQueueReport(si,DEFAULTSIZE));
        ReportLabels.add("Kitchen Queue");
        Reports.add(new GrillReport(si,DEFAULTSIZE));
        ReportLabels.add("Items Cooking");
        Reports.add(new StatisticsReport(si,DEFAULTSIZE));
        ReportLabels.add("Statistics");
    }
    
    private void CreateReportButtons() {
        for(int i = 0; i < Reports.size(); i++) {
            javax.swing.JToggleButton t = new javax.swing.JToggleButton(ReportLabels.get(i));
            t.addMouseListener(new ButtonClickListener(i));
            ReportButtonToolBar.add(t);
        }

    }
    
    private class ButtonClickListener extends java.awt.event.MouseAdapter {
        private final int ButtonIndex;
        public ButtonClickListener(int Index) {
            ButtonIndex = Index;
        }
 
        @Override
        public void mouseClicked(MouseEvent e) {
            ReportButtonStateChanged(e,ButtonIndex);
        }

    }
    
    public void UpdateAllReports() {
        for(Report ri: Reports) ri.Update();
        this.repaint();
    }
    


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ReportPanel = new javax.swing.JPanel();
        ReportButtonToolBar = new javax.swing.JToolBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout ReportPanelLayout = new javax.swing.GroupLayout(ReportPanel);
        ReportPanel.setLayout(ReportPanelLayout);
        ReportPanelLayout.setHorizontalGroup(
            ReportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 923, Short.MAX_VALUE)
        );
        ReportPanelLayout.setVerticalGroup(
            ReportPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 866, Short.MAX_VALUE)
        );

        ReportButtonToolBar.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        ReportButtonToolBar.setFloatable(false);
        ReportButtonToolBar.setRollover(true);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(ReportPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(ReportButtonToolBar, javax.swing.GroupLayout.PREFERRED_SIZE, 913, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(ReportButtonToolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ReportPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ReportButtonStateChanged(MouseEvent evt, int ButtonIndex) {
        javax.swing.JToggleButton t = (javax.swing.JToggleButton)evt.getSource();
        if(t.isSelected()) ReportPanel.add(Reports.get(ButtonIndex));
        else {ReportPanel.remove(Reports.get(ButtonIndex));  ReportPanel.validate();}
        this.repaint();
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(newManagerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(newManagerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(newManagerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(newManagerGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                //new newManagerGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToolBar ReportButtonToolBar;
    private javax.swing.JPanel ReportPanel;
    // End of variables declaration//GEN-END:variables
}
